package com.cn.kabalifeuser.ui.my.activity;

import com.cn.kabalifeuser.api.Api;
import com.cn.kabalifeuser.base.BasePresenter;
import com.cn.kabalifeuser.callback.CacheCallBack;
import com.cn.kabalifeuser.config.Constants;
import com.cn.kabalifeuser.ui.my.bean.FansBean;
import com.cn.kabalifeuser.ui.my.bean.FansListBean;
import com.cn.kabalifeuser.ui.release.bean.EmployedBusinessListBean;
import com.cn.kabalifeuser.utils.LoggerUtils;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;

/**
 * Created by 晓林 on 2020/9/4.
 * function:
 */
public class FansListPresenter extends BasePresenter<FansListView> {
    public void onFansData(String token) {
        OkGo.<FansBean>get(Api.API_USER_FANS)
                .headers("token", token)
                .execute(new CacheCallBack<FansBean>() {
                    @Override
                    public void onSuccess(Response<FansBean> response) {
                        super.onSuccess(response);
                        LoggerUtils.e("list：" + response.body());
                        if (isViewAttached())
                            if (response.body().getCode() == Constants.HTTP_SUCCESS)
                                getView().onFansSuccess(response.body());
                            else if (response.body().getCode() == Constants.HTTP_AGAIN_LOGIN)
                                getView().onReLoggedIn(response.body().getMsg());
                            else
                                getView().onError(response.body().getMsg());
                    }
                });
    }

    public void onFansListData(String token, int order, int sort, int page, int limit) {
        OkGo.<FansListBean>get(Api.API_USER_FANS_LIST)
                .headers("token", token)
                .params("limit", limit)
                .params("page", page)
                .params("order", order)
                .params("sort", sort)
                .execute(new CacheCallBack<FansListBean>() {
                    @Override
                    public void onSuccess(Response<FansListBean> response) {
                        super.onSuccess(response);
                        LoggerUtils.e("list：" + response.body());
                        if (isViewAttached())
                            if (response.body().getCode() == Constants.HTTP_SUCCESS)
                                getView().onFansListSuccess(response.body());
                            else if (response.body().getCode() == Constants.HTTP_AGAIN_LOGIN)
                                getView().onReLoggedIn(response.body().getMsg());
                            else
                                getView().onError(response.body().getMsg());
                    }
                });
    }
}
